package com.pat.web.controller;

import java.util.List;

import com.jfinal.core.Controller;
import com.jfinal.render.JsonRender;
import com.pat.web.ApiResponse;
import com.pat.web.NoNeedLogon;
import com.pat.web.model.CityInfo;
import com.pat.web.model.CountyInfo;
import com.pat.web.model.ProvinceInfo;

public class AreaController extends Controller{
	
	@NoNeedLogon
	public void getAreaInfoList(){
		ApiResponse response = new ApiResponse();
		List<CityInfo> cityInfos = CityInfo.dao.find("select * from city_info");
		response.setData(cityInfos);
		render(new JsonRender(response));
	}
	
	
	@NoNeedLogon
	public void getProvinceist(){
		ApiResponse response = new ApiResponse();
		List<ProvinceInfo> provinceInfos = ProvinceInfo.dao.find("select * from province_info");
		response.setData(provinceInfos);
		render(new JsonRender(response));
	}
	
	
	
	@NoNeedLogon
	public void getCityListByProvinceId(){
		ApiResponse response = new ApiResponse();
		List<CityInfo> cityInfos = CityInfo.dao.find("select * from city_info where province_id = ?",getParaToInt("provinceId"));
		response.setData(cityInfos);
		render(new JsonRender(response));
	}
	
	
	@NoNeedLogon
	public void getCountyListByCityId(){
		ApiResponse response = new ApiResponse();
		List<CountyInfo> countyInfos = CountyInfo.dao.find("select * from county_info where city_id = ?",getParaToInt("cityId"));
		response.setData(countyInfos);
		render(new JsonRender(response));
	}
	
}
